Workspace plotting
Starting the workspace plotter
The workspace plotter is a fast way to plot the variables in your
current workspace. No more errors from mistyping those long variable names.
Just type plt (with no arguments) at the command prompt and a
window will appear such as the one shown to the left. (This window was
generated with the included
wrkspace.m script example which creates the variables
listed and then calls plt with no arguments.) All the variables in your workspace (except for
scalars and strings) will be listed in the workspace plotter figure. The size of
the variable (row, column) appears right after the variable name. If your
workspace contains many variables, the variable list may appear in several
columns. If your workspace includes 1x1 structures with vector fields
(such as the bottom two variables in this figure),
then these fields will also appear in the workspace plotter figure using the
usual structure notation (struct.field)
Choosing an x-vector
The first thing you should do is select the x-vector that you want to plot
along the x-axis. As you can see from the instructions (in green) at the top of
the figure, you should do this by clicking on the desired x-vector using the
right1 mouse button. You
may click on any of the variables shown in white. Note that in this example, the
variable called long_variable_name is grayed out.
This is because only row or column vectors can be x-vectors. Since
long_variable_name has three rows of 400 elements it
can't be selected as an x-vector.
1 Actually in this initial situation you may
also select the x-vector with a left click. Usually, a left click is
used for selecting y-vectors, but since you can't do that without at least
one selected x-vector it assumes that you are choosing an x-vector in either case.
For consistency, you still might want to stick with the right click for selecting
the x-vector - a habit that probably will make workspace plotting easier.
Suppose you choose to plot the 400 element row vector sec
along the x axis. After you click on that vector, it turns red for identification
and visibility and the tag ←x
is placed after the variable name indicating this is the chosen x vector as
shown to the left.
Choosing a y-vector
Next, you must choose the array (or arrays) to plot along the y axis. The plot
routine requires that one of the dimensions of the y array match the length of
the x vector. So in this example, the y arrays must have either 400 rows or 400
columns. In this example, five of the variables do not meet this
condition, so they are grayed out and you will not be allowed to select
them.
Suppose you then click on these 3 array names:
long_variable_name, psvb1, and
s.psvb4. As you click on them, the names will turn
yellow and the tag ←y
is placed after the variable names to indicate that these arrays are to be
plotted along the y axis.
If you then click on the "Plot" button plt will create a plot containing five
traces. The first 3 traces will be the 3 rows of the array
long_variable_name. The fourth trace will contain the data from
psvb3 and the last trace will contain the data from
s.psvb4. (Note that the order of the traces will be
according to the order that the variables appear in the list and not on the order
that you clicked on them.)
By default, a maximum of 7 characters are used in the TraceID box which means that
some characters may be removed to make it fit. Note that the last character is always
included and underscores are removed to save space. Also note that for arrays with
more than one row or column a row or column index is attached to the end of the name.
Since a single x vector is being used, the x vector name (sec)
is used as the x-axis label. In this example, the y-axis is labeled with Y
axis for lack of anything better. If you had selected just a single
y-axis variable for plotting, that variable name would be used as the y-axis label.
Starting from the previous situation, suppose
the numbers in psvb1 were far bigger than the other selected y variables.
Then the other traces would be too small when plotted on the same y-axis
scale. One way to solve this problem is to plot psvb1 on the right hand axis
and leave the other variables on the left side. To do this, double click on
psvb1. Note that its color changes to orange and the ←y
changes to ←yR
to indicate that this variable will be plotted on the right hand axis. You
may select as many traces as you want for either the left or right hand axes.
To change a ←yR
(orange) to a ←y
(yellow) single click a few times on the variable name. (The exact number of
clicks depends somewhat on the situation.)
So far we have only selected a single x vector.
Although this will be sufficient most of the time, the workspace plotter
allows multiple x vectors to be selected. Suppose you now right-click on
seconds and vb2rep.
(Since they are grayed out, they won't accept a left click, but in this
situation, they will accept a right click). These two variables will then
turn red to indicate that they are to be used as x vectors. They will also
be marked with ←x2
and ←x3
respectively and the ←x
marking on sec will change
to ←x1.
The digits after the "x" make it easier to know
which x vector you have selected for each y vector. Also the first two
variables (b1catb3 and
b2catb4), which were grayed out before, now turn white because these
800-element row vectors now can be plotted versus either x2 or x3.
Suppose you then click once on both b1catb3 and
b2catb4. They will both turn yellow and be marked
with ←y2
indicating that they should be plotted with respect to
x2 (seconds). In this case, there is
more than one choice of x vectors, so if you click on
b2catb4 again, its mark changes from
←y2
to ←y3 as shown in
the figure to the left. Since there are no other possible x
vectors to choose from, if you click on b2catb4
one more time the ←y3
mark will disappear and the variable name will change back to white, indicating that it is
no longer selected.
Every time you click the "Plot" button, the workspace plotter will create
a new figure window containing the plot you specified by the various
←x
and ←y
tags. When you have created many plots, pressing the "CloseAll" button is a
convenient way to close all of these figure windows (although the workspace
browser window itself remains open).
If you have many long variable names, you may not be happy with TraceIDs of only 7 characters.
In that case, you can specify longer TraceID's tags by typing a
command such as TraceIDlen=17; before calling the
workspace plotter. (Try this before typing wrkspace).
However, you will notice one problem. The longer trace names will not fit in
the space reserved for the TraceID box and the characters will run into the
main plot axis. You could solve this problem by using a plt option variable,
which is any variable containing the characters pltopt
in the variable name. So for example the variables pltopt, pltopt2, another_pltoption
would all be recognized as plt option variables whereas variables pltOpt2
and another_plt_option would not be so recognized because it must contain
the string "pltopt" exactly (including case). An example of how a pltopt variable
can help follows:
Before starting wrkspace.m, try typing the following two lines at the command prompt:
TraceIDlen=17;
pltopt = {'xy', [0 .24 .12 .74 .86; -1 .01 .83 .2 .15]};
The first row of the xy parameter gives new coordinate locations for the plot (both left & right axes) and
the second row gives new coordinates for the TraceID box. These coordinates can be
generated easily by moving/resizing the objects with the mouse. (To see how look at the manual section
GUI building with plt).
If you wanted to make the two commands above permanent for all workspace plotting,
create a file on your Matlab path named pltdef.m
which contain those two lines. Below are more details about how to use pltdef.m
As an alternative to the 'xy' parameter used above you could use the 'AxisPos' parameter as follows:
pltopt = {'AxisPos',[1.8 1 .86 1 2.8]};
This would increase the width of the TraceID box by a factor of 2.8 while letting plt choose
the height of the TraceID box appropriately (an advantage over the 'xy' command). Unfortunately,
the AxisPos parameters can't be determined automatically with the GUI building tools. (The "1.8"
tells plt to make the blank space to the left of the axis 80% bigger to make more room for the
TraceIDs and the ".86" tells plt to make the plot width 86% of the former size so that the plot
doesn't run off the right edge.)
To see a list of all the possible commands you can insert into pltopt variables, see these sections of the manual
pltdef.m
If a file named pltdef.m exists on your Matlab path then that
file will be run before the workspace plotter is opened. This file may contain
any Matlab commands, and are usually used to define workspace plotter defaults and variables.
The workspace plotter looks for any variable that
contains the characters pltopt anywhere in its name. If it
finds any such variables it will use the parameters they contain as arguments to
plt when you press the "Plot" button. For example suppose
pltdef.m contains these two lines:
pltopt1 = {'Options','Menu','Title','This is a plot title'};
pltopt2 = {'FigName','Workspace plotter'};
Then any plot created by the workspace plotter will have its figure menu bar enabled (from Options),
its axis label will be set to 'Frame data' and its figure name will be set to 'Workspace plotter'.
pltdef.m may also include other variables or commands unrelated to
plotting options. For example, suppose pltdef.m included these three lines:
circleY = exp((0:.04:2)*pi*1j); % 50 point unit circle
circleX = real(circleY);
circleY = imag(circleY);
Then whenever you started the workspace plotter you would see circleX and circleY in
the workspace variables list. This would allow you to add a unit circle to your plot
by selecting these variables from the list (x vs. y) This would be quite useful if you
were often plotting z-plane poles and zeros, Nyquist data, or other data that lives in
the complex plane.